<template>
  <common-page
    ref="commonPage"
    :bg-path="bgPath"
    :web-path="webPath"
    :columns="columns"
    :search-items="searchItems"
    :form-items="formItems"
    :d-table-config="dTableConfig"
  />
</template>
<script>
export default {
  data() {
    return {
      // ===== ===== ===== ===== 全局属性 ===== ===== ===== =====
      // 后台接口路径
      bgPath: 'health/health/health/medbatch',
      // Web路径
      webPath: 'health/Health/Health/MedBatch',
      // ===== ===== ===== ===== 页面配置 ===== ===== ===== =====
      // 搜索内容
      searchItems: [
        {
          rowIndex: 1,
          items: [
            {
              code: "code",
              name: "编码",
              span: 6,
              type: "text",
              config: {
                edit: false
              }
            },
            {
              code: "name",
              name: "名称",
              span: 6,
              type: "text",
              config: {
                edit: false
              }
            },
            {
              code: "userCode",
              name: "用户编码",
              span: 6,
              type: "text",
              config: {
                edit: false
              }
            },
            {
              code: "userName",
              name: "用户名称",
              span: 6,
              type: "text",
              config: {
                edit: false
              }
            },
            {
              code: "minMedTime",
              name: "最早用药时间",
              type: "datetime",
              span: 6,
              config: {
                edit: false
              }
            },
            {
              code: "maxMedTime",
              name: "最晚用药时间",
              type: "datetime",
              span: 6,
              config: {
                edit: false
              }
            }
          ]
        }
      ],
      // 列表内容
      columns: [
        {
          code: "code",
          name: "编码",
          span: 6,
          type: "text",
          config: {
            edit: false
          }
        },
        {
          code: "name",
          name: "名称",
          span: 6,
          type: "text",
          config: {
            edit: false
          }
        },
        {
          code: "userCode",
          name: "用户编码",
          span: 6,
          type: "text",
          config: {
            edit: false
          }
        },
        {
          code: "userName",
          name: "用户名称",
          span: 6,
          type: "text",
          config: {
            edit: false
          }
        },
        {
          code: "medTime",
          name: "用药时间",
          type: "text",
          span: 6,
          config: {
            edit: false
          }
        }
      ],
      // 增加/修改/详情 表单
      formItems: [
        {
          rowIndex: 1,
          items: [
            {
              code: "code",
              name: "编码",
              span: 6,
              type: "text",
              config: {
                edit: false,
                rules: [
                  { required: true, message: '请输入编码', trigger: 'blur' }
                ]
              }
            },
            {
              code: "name",
              name: "名称",
              span: 6,
              type: "text",
              config: {
                edit: false,
                rules: [
                  { required: true, message: '请输入名称', trigger: 'blur' }
                ]
              }
            },
            {
              code: "userCode",
              span: 6,
              name: "用户编码",
              type: "popup",
              config: {
                url: "base/user/user/user",
                filedList: [
                  { code: 'id', name: 'ID' },
                  { code: 'code', name: '编码' },
                  { code: 'name', name: '名称' }
                ],
                searcher: {},
                defaultValue: "",
                minLength: 0,
                maxLength: 20,
                disabled: false,
                rules: [
                  { required: true, message: '请选择用户', trigger: 'change' }
                ]
              },
              handleEvent: {
                /**
                 * 开窗组件被选择
                 * @param code
                 * @param row
                 */
                onPopupClick: (code, row) => {
                  this.$refs.commonPage.updateFormData(code, row.code)
                  this.$refs.commonPage.updateFormData("userName", row.name)
                  this.$refs.commonPage.updateFormData("userId", row.id)
                }
              }
            },
            {
              code: "userName",
              name: "用户名称",
              span: 6,
              type: "text",
              config: {
                edit: false,
                disabled: true
              }
            },
            {
              code: "medTime",
              name: "用药时间",
              type: "time",
              span: 6,
              config: {
                edit: false
              }
            }
          ]
        }
      ],
      // 子表配置
      dTableConfig: [
        {
          key: "medBatchItem",
          name: "用药批次项",
          columns: [
            {
              code: "medCode",
              span: 6,
              name: "药品编码",
              type: "popup",
              config: {
                url: "base/dictionary/medicinedic/materiel",
                filedList: [
                  { code: 'id', name: 'ID', config: { align: "center" }},
                  { code: 'code', name: '编码', config: { align: "center" }},
                  { code: 'name', name: '名称', config: { align: "center" }}
                ],
                searcher: {},
                defaultValue: "",
                minLength: 0,
                maxLength: 20,
                disabled: false,
                require: true,
                rules: [
                  { required: true, message: '请选择药品', trigger: 'blur' }
                ]
              },
              handleEvent: {
                /**
                 * 开窗组件被选择
                 * @param line
                 * @param code
                 * @param row
                 */
                onPopupClick: (line, code, row) => {
                  this.$refs.commonPage.updateDTableData(line, "medBatchItem", "medName", row.name)
                  this.$refs.commonPage.updateDTableData(line, "medBatchItem", code, row.code)
                  this.$refs.commonPage.updateDTableData(line, "medBatchItem", "medId", row.id)
                }
              }
            },
            {
              code: "medName",
              name: "药品名称",
              type: "text",
              span: 6,
              config: {
                edit: false,
                disabled: true
              }
            },
            {
              code: "medBoxPositionSign",
              span: 6,
              name: "药箱位置",
              type: "popup",
              config: {
                url: "health/health/health/medbox",
                filedList: [
                  { code: 'id', name: 'ID', config: { align: "center" }},
                  {
                    code: 'positionSign',
                    name: '药箱位置标识',
                    type: "select",
                    config: {
                      align: "center",
                      options: [{ key: "1", value: "1号位" }, { key: "2", value: "2号位" }]
                    }
                  },
                  { code: 'medName', name: '药品名称', config: { align: "center" }}
                ],
                searcher: {},
                defaultValue: "",
                minLength: 0,
                maxLength: 20,
                disabled: false,
                require: true,
                rules: [
                  { required: true, message: '请选择药箱', trigger: 'blur' }
                ]
              },
              handleEvent: {
                /**
                 * 开窗组件被选择
                 * @param line
                 * @param code
                 * @param row
                 */
                onPopupClick: (line, code, row) => {
                  let value
                  switch (row.positionSign) {
                    case "1":
                      value = "1号位"
                      break
                    case "2":
                      value = "2号位"
                      break
                    default:
                      break
                  }
                  this.$refs.commonPage.updateDTableData(line, "medBatchItem", code, value)
                }
              }
            },
            {
              code: "medFreqCode",
              span: 6,
              name: "用药频次编码",
              type: "popup",
              config: {
                url: "base/dictionary/medicinedic/meddictionary",
                filedList: [
                  { code: 'id', name: 'ID', config: { align: "center" }},
                  { code: 'positionSign', name: '编码', config: { align: "center" }},
                  { code: 'name', name: '名称', config: { align: "center" }}
                ],
                searcher: {},
                defaultValue: "",
                minLength: 0,
                maxLength: 20,
                disabled: false,
                require: true,
                rules: [
                  { required: true, message: '请选择用药批次', trigger: 'change' }
                ]
              },
              handleEvent: {
                /**
                 * 开窗组件被选择
                 * @param line
                 * @param code
                 * @param row
                 */
                onPopupClick: (line, code, row) => {
                  this.$refs.commonPage.updateDTableData(line, "medBatchItem", "medFreqName", row.name)
                  this.$refs.commonPage.updateDTableData(line, "medBatchItem", code, row.code)
                  this.$refs.commonPage.updateDTableData(line, "medBatchItem", "medFreqId", row.id)
                }
              }
            },
            {
              code: "medFreqName",
              name: "用药批次名称",
              type: "text",
              span: 6,
              config: {
                edit: false,
                disabled: true
              }
            },
            {
              code: "doseNum",
              name: "用药剂量",
              span: 6,
              type: "number",
              config: {
                edit: false,
                precision: 2
              }
            }
          ]
        }
      ]
    }
  }
}
</script>
